// columns.ts

import DictTag, { DictValueEnum } from "@/components/DictTag";
import { createIcon } from "@/utils/IconUtil";
import { ProColumns } from "@ant-design/pro-table";
import { Avatar, Divider, Dropdown, MenuProps, Popconfirm, Space, Switch, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	statusOptions: DictValueEnum,
	sexOptions: DictValueEnum,
	handleColumnEditor: (record: API.Setting.UserVo) => void,
	handleColumnRemove: (record: API.Setting.UserVo) => void,
	handleColumnRealName: (record: API.Setting.UserVo) => void,
	handleColumnDetails: (record: API.Setting.UserVo) => void,
	handleDropdownClick: (key: string, record: API.Setting.UserVo) => void
): ProColumns<API.Setting.UserVo>[] => {
	return [
		{
			title: "姓名",
			dataIndex: "realName",
			valueType: "text",
			search: false,
			render: (_, record) => {
				return (
					<>
						{record?.avatar ? (
							<Space>
								<Avatar src={record?.avatar} size={35} />
								<Typography
									style={{ cursor: "pointer" }}
									onClick={() => {
										handleColumnRealName(record);
									}}
								>
									{record?.realName}
								</Typography>
							</Space>
						) : (
							<Space>
								<Avatar size={35} style={{ backgroundColor: "#2080f0", textAlign: "center", lineHeight: "35px" }}>
									{record?.realName?.charAt(0).toUpperCase()}
								</Avatar>
								<Typography
									style={{ cursor: "pointer" }}
									onClick={() => {
										handleColumnRealName(record);
									}}
								>
									{record?.realName}
								</Typography>
							</Space>
						)}
					</>
				);
			}
		},
		{
			title: "账号",
			dataIndex: "userName",
			valueType: "text"
		},
		{
			title: "电话",
			dataIndex: "phonenumber",
			valueType: "text",
			ellipsis: true
			// copyable: true
		},
		{
			title: "邮箱",
			dataIndex: "email",
			ellipsis: true,
			// copyable: true,
			valueType: "text"
		},
		// {
		// 	title: "性别",
		// 	dataIndex: "sex",
		// 	valueType: "select",
		// 	valueEnum: sexOptions,
		// 	render: (_, record) => {
		// 		return <DictTag enums={sexOptions} value={record.sex} />;
		// 	}
		// },
		{
			title: "状态",
			dataIndex: "status",
			valueType: "select",
			valueEnum: statusOptions,
			render: (_, record) => {
				return <DictTag enums={statusOptions} type="tag" value={record.status} />;
			}
		},
		{
			title: "操作",
			dataIndex: "option",
			width: "220px",
			valueType: "option",
			fixed: "right",
			render: (_, record: any) => {
				return (
					record?.id !== 1 && (
						<>
							<Space size={1} split={<Divider type="vertical" />}>
								<Typography.Link
									key="details"
									onClick={() => {
										handleColumnDetails(record);
									}}
								>
									详情
								</Typography.Link>
								<Typography.Link
									key="edit"
									onClick={() => {
										handleColumnEditor(record);
									}}
								>
									编辑
								</Typography.Link>
								<Popconfirm
									placement="bottomRight"
									title={"提示"}
									description={`确定删除角色：${record.roleName} 吗？`}
									onConfirm={() => {
										handleColumnRemove(record);
									}}
									okText="确认"
									cancelText="取消"
								>
									<Typography.Link type="danger" key="remove">
										删除
									</Typography.Link>
								</Popconfirm>
								<Dropdown
									trigger={["click"]}
									menu={{
										items: listOperItem,
										onClick: ({ key }) => {
											handleDropdownClick(key, record);
										}
									}}
								>
									<Typography.Link key="auth">更多</Typography.Link>
								</Dropdown>
							</Space>
						</>
					)
				);
			}
		}
	];
};
const listOperItem: MenuProps["items"] = [
	{
		label: "重置密码",
		key: "restPassword"
	},
	{
		label: "授权角色",
		key: "authRole"
	}
];
export const proTableCardProps = {
	bodyStyle: {
		paddingInline: 0,
		paddingBlock: 0
	}
};

export const pagination = {
	showQuickJumper: true,
	showSizeChanger: true
};

export const formTitle = ["添加用户", "编辑用户"];
